<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>守护云</title>
    <meta name="description" content="守护云">
    <meta name="keywords" content="守护云">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header" style="width: 600px;margin: 100px auto" >
        <div>
            修改密码
        </div>
        <div class="add-form" style="margin-top: 15px;">
                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                         label-width="100px">
                    <el-row>
                        <el-col :span="20">
                            <el-form-item label="旧密码" prop="passwordold">
                                <el-input v-model="formData.passwordold"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="20">
                            <el-form-item label="新密码" prop="passwordnew">
                                <el-input v-model="formData.passwordnew"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="20">
                            <el-form-item label="确定密码" prop="passwordnew2">
                                <el-input v-model="formData.passwordnew2"/>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="fanhui">取消</el-button>
                    <el-button type="primary" @click="editPassword()">确定</el-button>
                </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<!--异步请求-->
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            validate:"",
            rules: {//校验规则   在上面的标签通过prop与之关联
                passwordold: [{required: true, message: '密码为必填项', trigger: 'blur'}],
                passwordnew: [{required: true, message: '密码为必填项', trigger: 'blur'}],
                passwordnew2: [{required: true, message: '密码为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {

        },
        methods: {
           fanhui(){
               location.href = "/pages/main.html"
           },

            editPassword() {
                //进行表单校验
                this.$refs['dataAddForm'].validate((valid) => {
                    <!-- valid就是表单校验返回的一个boolen值  只要表单里设置了校验项  都会在提交的时候校验 -->
                    if (valid) {
                        //表单校验通过，发生ajax请求，将录入的数据提交到后台进行处理
                        console.log(this.formData);
                        axios.get("/user/jiaoyan.do?passwordold=" + this.formData.passwordold).then((res) => {
                            if (res.data.flag) {//执行成功
                                axios.post("/user/xiugai.do",this.formData).then((res) => {
                                    if (res.data.flag) {//执行成功
                                        location.href = "/login.html"
                                        this.$message({
                                            type: 'success',
                                            message: res.data.message
                                        })
                                    } else {//执行失败
                                        //弹出提示
                                        this.$message.error(res.data.message);
                                    }
                                })
                            } else {//执行失败
                                //弹出提示
                                this.$message.error(res.data.message);
                            }
                        });
                    } else {
                        //校验不通过
                        this.$message.error("输入信息是否正确！");
                        //重置表单  防止下次弹出表单显示上次添加数据
                        this.resetForm();
                        return false;
                    }
                });
            },

        }
    })
</script>
</html>